package com.hyk.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hyk.domain.CoinRecharge;
import com.hyk.dto.R;
import com.hyk.service.CoinRechargeService;
import com.hyk.utils.UserUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

@RestController
@RequestMapping("/coinRecharges")
@Api(tags = "充币记录控制器")
public class CoinRechargeController {

    @Resource
    private CoinRechargeService coinRechargeService;

    @GetMapping("/records")
    @ApiOperation("查询分页数据")
    public R<Page<CoinRecharge>> list(@ApiIgnore Page<CoinRecharge> page,
                                      Long coinId,
                                      Long userId,
                                      String userName,
                                      String mobile,
                                      Byte status,
                                      String numMin,
                                      String numMax,
                                      String startTime,
                                      String endTime){
        Page<CoinRecharge> page1 = coinRechargeService.findByPage(page,coinId,userId,userName,mobile,status,numMin,numMax,startTime,endTime);
        return R.ok(page1);
    }

    @GetMapping("/user/record")
    public R<Page<CoinRecharge>> list(Page<CoinRecharge> page, Long coinId) {
        Page<CoinRecharge> list = coinRechargeService.page(page, new LambdaQueryWrapper<CoinRecharge>()
                .eq(CoinRecharge::getUserId, UserUtils.getUser())
                .eq(coinId != null, CoinRecharge::getCoinId, coinId)
                .orderByDesc(CoinRecharge::getCreated));
        return R.ok(list);
    }

}
